<?php

/**
 * Controller_notice
 * 校内事务、审批设置、校长发布通知、通用发布通知、审核、家校互动
 */

	class Controller_notice extends MyApp {

		public function __construct()
		{

			parent::__construct();


			$this->model->department    = YOU::loadModel('department');
			$this->model->notice    	= YOU::loadModel('notice');
			$this->model->appoint    	= YOU::loadModel('appoint');
			$this->model->staff    		= YOU::loadModel('staff');
			$this->model->research    	= YOU::loadModel('research');
			$this->model->prepare    	= YOU::loadModel('prepare');
			$this->model->subject    	= YOU::loadModel('subject');
			$this->model->discipline    = YOU::loadModel('discipline');
			$this->model->grade         = YOU::loadModel('grade');
			$this->model->class         = YOU::loadModel('class');
			$this->model->student       = YOU::loadModel('student');
			$this->model->divide        = YOU::loadModel('divide');
			$this->model->user          = YOU::loadModel('user');
			$this->model->file          = YOU::loadModel('file');
			$this->model->audit         = YOU::loadModel('audit');

		}
		/** 首页 **/
		public function actionIndex()
		{

			$this->tpl->display();
		}

		/** 校内事务列表 **/
		public function actionList ()
		{

			// 权限
			$staff_app = $this->model->appoint->getTeacherRow($this->user['type_id']);
			// 上级部门
			$up_lists = $this->model->department->getUpAll();
			// 查询条件

			$notice_title		= $this->get->notice_title;
			$staff_name			= $this->get->staff_name;
			$from				= $this->get->from;
			$to					= $this->get->to;
			$where = " ";
			//搜索条件
			if(!empty($notice_title)){

				$where .= " AND a.notice_title LIKE '%{$notice_title}%'";
				$this->tpl->assign("notice_title", $notice_title);
			}
			if(!empty($staff_name)){
				$row = $this->model->staff->getNameMAll($staff_name);
				
				//$row = $this->model->user->getIdByType('staff',$row['staff_id']);
				
				$where .= " AND a.user_id ='{$row}'";
				$this->tpl->assign("staff_name", $staff_name);
			}
			if(!empty($from)){
				
				$where .= " AND a.end_time >= '{$from}'";
				$this->tpl->assign("from", $from);
			}
			if(!empty($to)){

				$where .= " AND a.end_time <= '{$to}+1'";
				$this->tpl->assign("to", $to);
			}
			// 完成
			if ($_POST) {
				$notice_id		= $this->post->notice_id;

				// 写入数据库
				$info = array(

				"is_show"				=> 1,
				"is_read"				=> 1,
				"read_time"             => date("Y-m-d"),

				);
				$this->db->do_update("tbl_notice_read", $info, "notice_id='{$notice_id}' AND read_to='{$this->user['user_id']}'");
			}
			// 校内事务
			$notice_type = 5;
	
			$notice_lists = $this->db->fetchAll("SELECT DISTINCT a.notice_id as r ,a.*,b.* FROM `tbl_notice` AS a,`tbl_notice_read` AS b WHERE a.notice_id = b.notice_id AND b.read_to = '{$this->user['user_id']}'  AND a.notice_type='{$notice_type}' {$where} ORDER BY a.notice_id DESC ");
		
			foreach ($notice_lists as $key => $value){
				// 提交者
				$notice_lists[$key]['user_name'] = $this->model->user->getNameById($value['user_id']);
				// 发布时间
				$notice_lists[$key]['create_time']  = date('Y-m-d',strtotime($value['create_time']));
				// 内容解密
				$notice_lists[$key]['notice_content'] =base64_decode($notice_lists[$key]['notice_content']);
				// 控制标题字数
				$notice_lists[$key]['notice_title'] = mb_substr($value['notice_title'],0,30,'utf8');
				if(strlen($notice_lists[$key]['notice_title'])>10){
					$notice_lists[$key]['notice_title']=$notice_lists[$key]['notice_title'].'...';

				}
			}

			$this->tpl->assign("notice_lists", $notice_lists);
			$this->tpl->assign("user", $this->user['user_id']);
			$this->tpl->assign("staff_app", $staff_app);
			$this->tpl->display('notice/m.notice.list.tpl.php');

		}
		// 校内事务添加
		public function actionAdd ()
		{
			$notice_id		= $this->get->notice_id;
			$notice_data    = $this->model->notice->getInfo($notice_id);

			if ($_POST){

				$notice_title				= $this->post->notice_title;
				$end_time					= $this->post->end_time;
				$notice_content				= $this->post->notice_content;
				$pid 						= $this->post->pid;
				$notice_content = base64_encode($notice_content);
				if(empty($notice_title)){
					Helper_Client::alert("请选择标题");
				}
				if(empty($pid)){
					Helper_Client::alert("请选择阅读对象");
				}

				// 写入数据库
				$info = array(

				"notice_title"			=> $notice_title,
				"end_time"				=> $end_time,
				"notice_content"      	=> $notice_content,
				"user_id"				=> $this->user['user_id'],
				"notice_type"      		=> 5,
				"status"                => 1,
				"create_time"           => date("Y-m-d H:i:s"),
				"update_time"           => "0000-00-00 00:00:00",

				);
				$this->db->do_insert("tbl_notice", $info);
				$notice_id = $this->db->insert_id();
				// 附件上传
				$file = $this->model->file->upload("notice_file", $notice_id, array("txt","ppt", "xls", "xlsx", "docs", "docx","doc", "pdf", "jpg", "png", "gif", "zip",
				"rar"));
				if (!empty($file)){
					$info = array(
					"notice_file" =>  $file['fname'],
					);

					$this->db->do_update("tbl_notice", $info, "notice_id='{$notice_id}'");
				}

				// 查找通知表最后一条获取id
				$notice_end = $this->model->notice->getEnd();
				// 查找阅读表
				$read_data = $this->model->notice->getReadRow($notice_end['notice_id'],$user_id);
				// 阅读表插入
				foreach ($pid as $key => $value){

					if (substr($value,0,4) == 'user') {
						$user_id = substr($value,5,13);

						if (empty($read_data)) {

							$info = array(
							"notice_id"   			=> $notice_end['notice_id'],
							"read_to"     			=> $user_id,
							"read_form"   			=> $this->user['user_id'],
							"is_show"     			=> 0,
							"is_read"     			=> 0,
							"status"                => 1,
							"create_time"           => date("Y-m-d H:i:s"),
							"update_time"           => "0000-00-00 00:00:00",
							);
							$this->db->do_insert("tbl_notice_read", $info);

						}
					}
				}
				if (empty($read_data)) {

					$info = array(
					"notice_id"   			=> $notice_end['notice_id'],
					"read_to"     			=> $this->user['user_id'],
					"read_form"   			=> $this->user['user_id'],
					// is_show =2 自己发的
					"is_show"     			=> 2,
					"is_read"     			=> 0,
					"status"                => 1,
					"create_time"           => date("Y-m-d H:i:s"),
					"update_time"           => "0000-00-00 00:00:00",
					);
					$this->db->do_insert("tbl_notice_read", $info);

				}
				// 跳转
				Helper_Client::location("发布成功", "index.php?a=notice.list");
			}

			//  树状图
			// 所有部门名称
			$department_lists = $this->model->department->getAll();
			// 所有部门任职人员
			$department_name = $this->model->appoint->getSAll();
			foreach ($department_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$department_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
				$department_name[$key]['staff_name'] = $row['staff_name'];
			}

			// 所有教研组名称
			$research_lists = $this->model->research->getAll();
			// 所有教研组的任职人员
			$research_name = $this->model->appoint->getRAll();
			foreach ($research_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$research_name[$key]['staff_name'] = $row['staff_name'];
				$research_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			}

			// 所有备课组名称
			$prepare_lists = $this->model->prepare->getAll();
			// 所有备课组的任职人员
			$prepare_name = $this->model->appoint->getPAll();
			foreach ($prepare_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$prepare_name[$key]['staff_name'] = $row['staff_name'];
				$prepare_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			}

			// 学科组
			$discipline_lists = $this->model->discipline->getAll();
			// 所有备课组的任职人员
			$discipline_name = $this->model->appoint->getDAll();
			foreach ($discipline_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$discipline_name[$key]['staff_name'] = $row['staff_name'];
				$discipline_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			}

			// 年级列表
			$grade_lists = $this->model->grade->getIni();
			// 班级列表
			$class_lists = $this->model->class->getAll();
			// 学生按 年级 班级 列出
			$student_lists = $this->db->fetchAll("SELECT a.user_id,b.student_name,b.class_id,b.grade_id FROM `tbl_user` AS a,`tbl_student` AS b WHERE a.type_id=b.student_id");

			$this->tpl->assign("department_lists", $department_lists);
			$this->tpl->assign("department_name", $department_name);
			$this->tpl->assign("research_lists", $research_lists);
			$this->tpl->assign("research_name", $research_name);

			$this->tpl->assign("prepare_lists", $prepare_lists);
			$this->tpl->assign("prepare_name", $prepare_name);
			$this->tpl->assign("discipline_lists", $discipline_lists);
			$this->tpl->assign("discipline_name", $discipline_name);

			$this->tpl->assign("grade_lists", $grade_lists);
			$this->tpl->assign("class_lists", $class_lists);
			$this->tpl->assign("student_lists", $student_lists);
			$this->tpl->assign("notice_data", $notice_data);

			$this->tpl->display('notice/m.notice.add.tpl.php');

		}
		/** 校内事务删除 **/
		public function actionDel()
		{
			// 类型
			$notice_id	      = (int)$this->get->notice_id;
			$notice_data = $this->db->fetchRow("select * from `tbl_notice` WHERE `user_id` = {$notice_id}");
			$uid = $this->user['user_id'];

			if($notice_data['user_id']  && ($uid !=$notice_data['user_id']) ){
				Helper_Client::alert("对不起无此权限");
				exit;
			}
			$this->db->query("DELETE  FROM `tbl_notice` WHERE notice_id='{$notice_id}'");
			$this->db->query("DELETE  FROM `tbl_notice_read` WHERE notice_id='{$notice_id}'");
			// 跳转
			Helper_Client::location("删除成功", "index.php?a=notice.list");

		}
		/** 校内事务详情 **/
		public function actionDetails()
		{

			$notice_id	      	= (int)$this->get->notice_id;
			$notice_data 		= $this->model->notice->getinfo($notice_id);
			$notice_data['notice_content'] = base64_decode($notice_data['notice_content']);
			// 已经阅读
			$info = array(
			"is_read"     			=> 1,
			);
			$this->db->do_update("tbl_notice_read", $info, "notice_id='{$notice_id}' AND read_to='{$this->user['user_id']}'");
			//  发布人
			$staff_xname 		= $this->model->staff->getinfo($notice_data['user_id']);
			$notice_data['staff_xname'] = $staff_xname['staff_name'];

			// 时间
			$notice_data['create_time'] = date('Y-m-d',strtotime($notice_data['create_time']));

			// 阅读人员记录，学生，老师
			$department_name = $this->model->notice->getReadAll($notice_id);
			foreach ($department_name as $key => $value){

				$row = $this->model->user->getNameByIdTo($value['read_to']);

				if (!empty($row['staff_name'])) {

					$staff_name[$key]['staff_name'] = $row['staff_name'];
					$staff_name[$key]['is_read'] = $value['is_read'];

				}
				if (!empty($row['student_name'])) {
					$student_name[$key]['student_name'] = $row['student_name'];
					$student_name[$key]['is_read'] = $value['is_read'];
				}

				// 判断是否阅读
				$row = $this->model->notice->getReadInfo($value['staff_id']);
				$department_name[$key]['is_read'] = $row['is_read'];
			}

			$this->tpl->assign("staff_name", $staff_name);
			$this->tpl->assign("student_name", $student_name);
			$this->tpl->assign("student_xname", $student_xname);

			$this->tpl->assign("notice_data", $notice_data);
			$this->tpl->display('notice/notice.details.tpl.php');
		}
		/** ------------------------- 校长发布通知---------------------------------- **/
		/** 校长发布通知列表 **/
		public function actionPresidentList ()
		{	
			// 发布部门
			$department_lists = $this->model->department->getAll();
			// 查询条件

			$notice_title		= $this->get->notice_title;
			$department_id		= $this->get->department_id;
			$from				= $this->get->from;
			$to					= $this->get->to;
			$where = " ";
			//搜索条件
			if(!empty($notice_title)){

				$where .= " AND notice_title LIKE '%{$notice_title}%'";
				$this->tpl->assign("notice_title", $notice_title);
			}
			if(!empty($department_id)){

				$where .= " AND department_id ='{$department_id}'";
				$this->tpl->assign("department_id", $department_id);
			}
			if(!empty($from)){

				$where .= " AND start_time >= '{$from}'";
				$this->tpl->assign("from", $from);
			}
			if(!empty($to)){
				
				$where .= " AND start_time <= '{$to}+1'";
				$this->tpl->assign("to", $to);
			}
			// 2=校长室发布通知
			$notice_tye  =2;
		
			$notice_lists = $this->db->fetchAll("SELECT * FROM `tbl_notice` WHERE notice_type={$notice_tye} {$where} ORDER BY notice_id DESC ");

			foreach ($notice_lists as $key => $value){
				// 部门名称
				$row = $this->model->department->getinfo($value['department_id']);
				$notice_lists[$key]['department_name']= $row['department_name'];
				// 内容解密
				$notice_lists[$key]['notice_content']=base64_decode($notice_lists[$key]['notice_content']);
				// 控制标题字数
				$notice_lists[$key]['notice_title'] = mb_substr($value['notice_title'],0,30,'utf8');
				if(strlen($notice_lists[$key]['notice_title'])>10){
					$notice_lists[$key]['notice_title']=$notice_lists[$key]['notice_title'].'...';

				}
			}

			
			$this->tpl->assign("notice_lists", $notice_lists);
			$this->tpl->assign("user", $this->user['user_id']);
			$this->tpl->assign("department_lists", $department_lists);

			$this->tpl->assign("notice_type", $notice_type);
			$this->tpl->display('notice/m.president.list.tpl.php');

		}
		/** 校长发布通知添加 **/
		public function actionPresidentAdd ()
		{
			
			// 发布部门
			$department_lists = $this->model->department->getAll();
			if ($_POST) {

				$notice_title		= $this->post->notice_title;
				$start_time		    = $this->post->start_time;
				$notice_content		= $this->post->notice_content;
				$department_id		= $this->post->department_id;
				$pid 				= $this->post->pid;
				$notice_content =base64_encode($notice_content);
				if(empty($notice_title)){
					Helper_Client::alert("请填写通知标题");
				}
				if(empty($start_time)){
					Helper_Client::alert("请填写通知时间");
				}
				if(empty($notice_content)){
					Helper_Client::alert("请填通知内容");
				}
				if(empty($pid)){
					Helper_Client::alert("请选择阅读对象");
				}


				// 写入数据库
				$info = array(
				"notice_title"   => $notice_title,
				"notice_content" => $notice_content,
				"department_id"  => $department_id,
				"user_id"    	 => $this->user['user_id'],
				"start_time"     => $start_time,
				"is_show"     	 => 2,
				"notice_type" 	 => 2,
				"status"         => 1,
				"create_time"  	 => date("Y-m-d H:i:s"),
				"update_time"  	 => "0000-00-00 00:00:00",
				);
				$this->db->do_insert("tbl_notice", $info);
				$notice_id = $this->db->insert_id();

				// 附件上传
				$file = $this->model->file->upload("notice_file", $notice_id, array("txt","ppt", "xls", "xlsx", "docs", "docx","doc", "pdf", "jpg", "png", "gif", "zip",
				"rar"));
				if (!empty($file)){
					$info = array(
					"notice_file" => $file['fname'],
					);

					$this->db->do_update("tbl_notice", $info, "notice_id='{$notice_id}'");
				}
				// 查找通知表最后一条获取id
				$notice_end = $this->model->notice->getEnd();

				// 阅读表插入
				foreach ($pid as $key => $value){

					if (substr($value,0,4) == 'user') {
						$user_id = substr($value,5,13);

						// 查找阅读表
						$read_data = $this->model->notice->getReadRow($notice_end['notice_id'],$user_id);

						if (empty($read_data)) {

							$info = array(
							"notice_id"   			=> $notice_end['notice_id'],
							"read_to"     			=> $user_id,
							"read_form"   			=> $this->user['user_id'],
							"is_read"     			=> 0,
							"status"                => 1,
							"create_time"           => date("Y-m-d H:i:s"),
							"update_time"           => "0000-00-00 00:00:00",
							);
							$this->db->do_insert("tbl_notice_read", $info);

						}
					}
				}
				// 跳转
				Helper_Client::reurl("index.php?a=notice.presidentlist&notice_type=2");

			}
			//  树状图
			// 所有部门名称
			$department_lists = $this->model->department->getAll();
			// 所有部门任职人员
			$department_name = $this->model->appoint->getSAll();
			foreach ($department_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$department_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
				$department_name[$key]['staff_name'] = $row['staff_name'];
			}

			// 所有教研组名称
			$research_lists = $this->model->research->getAll();
			// 所有教研组的任职人员
			$research_name = $this->model->appoint->getRAll();
			foreach ($research_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$research_name[$key]['staff_name'] = $row['staff_name'];
				$research_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			}

			// 所有备课组名称
			$prepare_lists = $this->model->prepare->getAll();
			// 所有备课组的任职人员
			$prepare_name = $this->model->appoint->getPAll();
			foreach ($prepare_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$prepare_name[$key]['staff_name'] = $row['staff_name'];
				$prepare_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			}

			// 学科组
			$discipline_lists = $this->model->discipline->getAll();
			// 所有备课组的任职人员
			$discipline_name = $this->model->appoint->getDAll();
			foreach ($discipline_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$discipline_name[$key]['staff_name'] = $row['staff_name'];
				$discipline_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			}

			// 年级列表
			$grade_lists = $this->model->grade->getIni();
			// 班级列表
			$class_lists = $this->model->class->getAll();
			// 学生按 年级 班级 列出
			$student_lists = $this->db->fetchAll("SELECT a.user_id,b.student_name,b.class_id,b.grade_id FROM `tbl_user` AS a,`tbl_student` AS b WHERE a.type_id=b.student_id");

			$this->tpl->assign("department_lists", $department_lists);
			$this->tpl->assign("department_name", $department_name);
			$this->tpl->assign("research_lists", $research_lists);
			$this->tpl->assign("research_name", $research_name);

			$this->tpl->assign("prepare_lists", $prepare_lists);
			$this->tpl->assign("prepare_name", $prepare_name);
			$this->tpl->assign("discipline_lists", $discipline_lists);
			$this->tpl->assign("discipline_name", $discipline_name);

			$this->tpl->assign("grade_lists", $grade_lists);
			$this->tpl->assign("class_lists", $class_lists);
			$this->tpl->assign("student_lists", $student_lists);

			$this->tpl->display('notice/m.president.add.tpl.php');
		}
		/** 校内事务删除 **/
		public function actionPresidentDel()
		{
			// 类型
			$notice_id	      = (int)$this->get->notice_id;
			$notice_data = $this->db->fetchRow("select * from `tbl_notice` WHERE `user_id` = {$notice_id}");
			$uid = $this->user['user_id'];

			if($notice_data['user_id']  && ($uid !=$notice_data['user_id']) ){
				Helper_Client::alert("对不起无此权限");
				exit;
			}
			$this->db->query("DELETE  FROM `tbl_notice` WHERE notice_id='{$notice_id}'");
			$this->db->query("DELETE  FROM `tbl_notice_read` WHERE notice_id='{$notice_id}'");
			// 跳转
			Helper_Client::location("删除成功", "index.php?a=notice.presidentlist");

		}
		/** 校内事务详情**/
		public function actionPresidentDetails()
		{
			$notice_id	      	= (int)$this->get->notice_id;
			$notice_data 		= $this->model->notice->getinfo($notice_id);
			$notice_data['notice_content']=base64_decode($notice_data['notice_content']);
			// 阅读
			$info = array(
			"is_read"     			=> 1,
			);
			$this->db->do_update("tbl_notice_read", $info, "notice_id='{$notice_id}' AND read_to ='{$this->user['user_id']}'");
			//  发布人
			$row 		= $this->model->department->getinfo($notice_data['department_id']);
			$notice_data['department_name'] = $row['department_name'];
			// 时间
			$notice_data['create_time'] = date('Y-m-d',strtotime($notice_data['create_time']));

			// 阅读人员记录，学生，老师
			$department_name = $this->model->notice->getReadAll($notice_id);
			foreach ($department_name as $key => $value){
				$row = $this->model->user->getInfo($value['read_to']);

				if($row['user_type']=='staff'){
					$c = $this->model->user->getNameById($row['user_id']);
					if (!empty($c)) {
						$staff_name[$key]['staff_name'] = $c;
						$staff_name[$key]['is_read'] = $value['is_read'];
					}

				}
				if($row['user_type']=='student'){
					$c = $this->model->user->getNameById($row['user_id']);
					if (!empty($c)) {
						$student_name[$key]['student_name'] = $c;
						$student_name[$key]['is_read'] = $value['is_read'];
					}
				}

				// 判断是否阅读
				$row = $this->model->notice->getReadInfo($value['staff_id']);
				$department_name[$key]['is_read'] = $row['is_read'];
			}

			$this->tpl->assign("staff_name", $staff_name);
			$this->tpl->assign("student_name", $student_name);

			$this->tpl->assign("notice_data", $notice_data);
			$this->tpl->display('notice/m.president.details.tpl.php');
		}
		/** ------------------------ 通用事项 发布通知 -------------------------- **/
		/** 通用事项----通知列表（无权限只能查看）**/
		public function actionCommonList()
		{
			// 当前时间
			$time = date('Y-m-d',time());
			// 权限
			$appoint_lists = $this->model->appoint->getStaffType($this->user['type_id']);
			if (empty($appoint_lists)) {
				// 无权限
				$appoint_lists =1;
			}

			// 发布部门
			$department_lists = $this->model->department->getAll();

			// 查询条件

			$notice_title		= $this->get->notice_title;
			$department_id		= $this->get->department_id;
			$from				= $this->get->from;
			$to					= $this->get->to;
			$where = " ";
			//搜索条件
			if(!empty($notice_title)){

				$where .= " AND a.notice_title LIKE '%{$notice_title}%'";
				$this->tpl->assign("notice_title", $notice_title);
			}
			if(!empty($department_id)){

				$where .= " AND a.department_id ='{$department_id}'";
				$this->tpl->assign("department_id", $department_id);
			}
			if(!empty($from)){

				$where .= " AND a.start_time >= '{$from}'";
				$this->tpl->assign("from", $from);
			}
			if(!empty($to)){

				$where .= " AND a.start_time <= '{$to}+1'";
				$this->tpl->assign("to", $to);
			}
			// 3=通用事项通知
			$notice_tye  =3;

			$notice_lists = $this->db->fetchAll("SELECT * FROM `tbl_notice` AS a,`tbl_notice_read` AS b WHERE a.notice_id = b.notice_id AND a.notice_type IN(2,3) AND b.read_to ='{$this->user['user_id']}' AND a.is_show IN(1,3) AND a.start_time<='{$time}' {$where} ORDER BY a.notice_id DESC ");

			foreach ($notice_lists as $key => $value){
				// 部门名称
				$row = $this->model->department->getinfo($value['department_id']);
				$notice_lists[$key]['department_name']= $row['department_name'];
				// 内容解密
				$notice_lists[$key]['notice_content'] = base64_decode($notice_lists[$key]['notice_content']);
				// 控制标题字数
				$notice_lists[$key]['notice_title'] = mb_substr($value['notice_title'],0,30,'utf8');
				if(strlen($notice_lists[$key]['notice_title'])>10){
					$notice_lists[$key]['notice_title']=$notice_lists[$key]['notice_title'].'...';

				}
			}

			$this->tpl->assign("notice_lists", $notice_lists);
			$this->tpl->assign("user", $this->user['user_id']);
			$this->tpl->assign("department_lists", $department_lists);

			$this->tpl->assign("notice_type", $notice_type);
			$this->tpl->assign("appoint_lists", $appoint_lists);
			$this->tpl->display('notice/m.common.list.tpl.php');
		}
		/** 通用事项----发布通知列表（有权限发布通知）**/
		public function actionCommonIssueList()
		{

			// 发布部门
			$department_lists = $this->model->department->getAll();

			// 查询条件

			$notice_title		= $this->get->notice_title;
			$department_id		= $this->get->department_id;
			$from				= $this->get->from;
			$to					= $this->get->to;
			$where = " ";
			//搜索条件
			if(!empty($notice_title)){

				$where .= " AND notice_title LIKE '%{$notice_title}%'";
				$this->tpl->assign("notice_title", $notice_title);
			}
			if(!empty($department_id)){

				$where .= " AND department_id ='{$department_id}'";
				$this->tpl->assign("department_id", $department_id);
			}
			if(!empty($from)){

				$where .= " AND create_time >= '{$from}'";
				$this->tpl->assign("from", $from);
			}
			if(!empty($to)){

				$where .= " AND create_time <= '{$to}'";
				$this->tpl->assign("to", $to);
			}
			// 3=通用事项通知
			$notice_type  =3;


			$notice_lists = $this->db->fetchAll("SELECT * FROM `tbl_notice`  WHERE notice_type = {$notice_type} AND user_id ={$this->user['user_id']} {$where} ORDER BY notice_id DESC ");
			foreach ($notice_lists as $key => $value){
				// 部门名称
				$row = $this->model->department->getinfo($value['department_id']);
				$notice_lists[$key]['department_name']= $row['department_name'];
				// 内容解密
				$notice_lists[$key]['notice_content'] =base64_decode($notice_lists[$key]['notice_content']);
				// 控制标题字数
				$notice_lists[$key]['notice_title'] = mb_substr($value['notice_title'],0,30,'utf8');
				if(strlen($notice_lists[$key]['notice_title'])>10){
					$notice_lists[$key]['notice_title']=$notice_lists[$key]['notice_title'].'...';
							
				}
				// 审核状态
				$notice_lists[$key]['is_show'] = $this->inform_judge[$value['is_show']];
			}

			$this->tpl->assign("notice_lists", $notice_lists);
			$this->tpl->assign("user", $this->user['user_id']);
			$this->tpl->assign("department_lists", $department_lists);

			$this->tpl->assign("notice_type", $notice_type);
			$this->tpl->assign("appoint_lists", $appoint_lists);
			$this->tpl->display('notice/m.common.issue.list.tpl.php');
		}
		/** 通用事项 -发布通知详情（有权限）**/
		public function actionCommonIssueDetails()
		{
			$notice_id	      	= (int)$this->get->notice_id;
			// 已经阅读
			$info = array(
			"is_read"     			=> 1,
			);
			$this->db->do_update("tbl_notice_read", $info, "notice_id='{$notice_id}' AND read_to='{$this->user['user_id']}'");
			$notice_data 		= $this->model->notice->getinfo($notice_id);
			// 内容解密
			$notice_data['notice_content'] = base64_decode($notice_data['notice_content']);
			//  发布人
			$row 		= $this->model->department->getinfo($notice_data['department_id']);
			$notice_data['department_name'] = $row['department_name'];
			// 时间
			$notice_data['create_time'] = date('Y-m-d',strtotime($notice_data['create_time']));
			// 审批结果
			$notice_data['is_show'] = $this->inform_judge[$notice_data['is_show']];
			// 阅读人员记录，学生，老师
			$department_name = $this->model->notice->getReadAll($notice_id);
			foreach ($department_name as $key => $value){
				$row = $this->model->user->getInfo($value['read_to']);

				if($row['user_type']=='staff'){
					$c = $this->model->user->getNameById($row['user_id']);
					if (!empty($c)) {
						$staff_name[$key]['staff_name'] = $c;
						$staff_name[$key]['is_read'] = $value['is_read'];
					}

				}
				if($row['user_type']=='student'){
					$c = $this->model->user->getNameById($row['user_id']);
					if (!empty($c)) {
						$student_name[$key]['student_name'] = $c;
						$student_name[$key]['is_read'] = $value['is_read'];
					}
				}

				// 判断是否阅读
				$row = $this->model->notice->getReadInfo($value['staff_id']);
				$department_name[$key]['is_read'] = $row['is_read'];
			}

			$this->tpl->assign("staff_name", $staff_name);
			$this->tpl->assign("student_name", $student_name);

			$this->tpl->assign("notice_data", $notice_data);
			$this->tpl->display('notice/m.common.issue.details.tpl.php');
		}
		/** 通用事项 -通知详情（）**/
		public function actionCommonDetails()
		{
			$notice_id	      	= (int)$this->get->notice_id;
			$notice_data 		= $this->model->notice->getinfo($notice_id);
			// 内容解密
			$notice_data['notice_content'] = base64_decode($notice_data['notice_content']);
			// 阅读
			$info = array(
			"is_read"     			=> 1,
			);
			$this->db->do_update("tbl_notice_read", $info, "notice_id='{$notice_id}' AND read_to='{$this->user['user_id']}'");
			//  发布人
			$row 		= $this->model->department->getinfo($notice_data['department_id']);
			$notice_data['department_name'] = $row['department_name'];
			// 时间
			$notice_data['create_time'] = date('Y-m-d',strtotime($notice_data['create_time']));

			// 阅读人员记录，学生，老师
			$department_name = $this->model->notice->getReadAll($notice_id);
			foreach ($department_name as $key => $value){
				$row = $this->model->user->getInfo($value['read_to']);
				if($row['user_type']=='staff'){
					$c = $this->model->user->getNameById($row['user_id']);
					if (!empty($c)) {
						$staff_name[$key]['staff_name'] = $c;
						$staff_name[$key]['is_read'] = $value['is_read'];
					}

				}
				if($row['user_type']=='student'){
					$c = $this->model->user->getNameById($row['user_id']);
					if (!empty($c)) {
						$student_name[$key]['student_name'] = $c;
						$student_name[$key]['is_read'] = $value['is_read'];
					}
				}

				// 判断是否阅读
				$row = $this->model->notice->getReadInfo($value['staff_id']);
				$department_name[$key]['is_read'] = $row['is_read'];
			}

			$this->tpl->assign("staff_name", $staff_name);
			$this->tpl->assign("student_name", $student_name);

			$this->tpl->assign("notice_data", $notice_data);
			$this->tpl->display('notice/m.common.details.tpl.php');
		}
		/** 通用事项 - 通知添加 **/
		public function actionCommonAdd ()
		{

			// 发布部门
			$department_lists = $this->model->department->getAll();
			$notice_type 			= $this->get->notice_type;
			$this->tpl->assign('notice_type',$notice_type);

			if ($_POST) {

				$notice_title		= $this->post->notice_title;
				$start_time		    = $this->post->start_time;
				$notice_content		= $this->post->notice_content;
				$department_id		= $this->post->department_id;
				$pid 				= $this->post->pid;
				$research			= $this->post->research;
				$prepare			= $this->post->prepare;
				$discipline			= $this->post->discipline;
				$grade				= $this->post->grade;
				$notice_content = base64_encode($notice_content);
				if(empty($notice_title)){
					Helper_Client::alert("请填写通知标题");
				}
				if(empty($start_time)){
					Helper_Client::alert("请填写通知时间");
				}
				if(empty($notice_content)){
					Helper_Client::alert("请填通知内容");
				}
				if(empty($pid)){
					Helper_Client::alert("请选择阅读对象");
				}
				// 发布部门
				if (!empty($department_id)) {
					$audit_type = 'department';
					$type_id    =$department_id;
				}
				if (!empty($research)) {
					$audit_type = 'research';
					$type_id    =0;
				}
				if (!empty($prepare)) {
					$audit_type = 'prepare';
					$type_id    =0;
				}
				if (!empty($discipline)) {
					$audit_type = 'discipline';
					$type_id    =0;
				}
				if (!empty($grade)) {
					$audit_type = 'grade';
					$type_id    =0;
				}
				// 写入数据库
				$info = array(
				"notice_title"   => $notice_title,
				"notice_content" => $notice_content,
				"department_id"  => $department_id,
				"user_id"    	 => $this->user['user_id'],
				"start_time"     => $start_time,
				"notice_type" 	 => $notice_type,
				"audit_type" 	 => $audit_type,
				"type_id" 	 	 => $type_id,
				// 未审核
				"is_show" 		 => 0,
				"status"         => 1,
				"create_time"  	 => date("Y-m-d H:i:s"),
				"update_time"  	 => "0000-00-00 00:00:00",
				);
				$this->db->do_insert("tbl_notice", $info);
				$notice_id = $this->db->insert_id();

				// 附件上传
				$file = $this->model->file->upload("notice_file", $notice_id, array("txt","ppt", "xls", "xlsx", "docs", "doc", "pdf", "jpg", "png", "gif", "zip", "rar"));
				if (!empty($file)){
					$info = array(
					"notice_file" => $file['fname'],
					);

					$this->db->do_update("tbl_notice", $info, "notice_id='{$notice_id}'");
				}
				// 查找通知表最后一条获取id
				$notice_end = $this->model->notice->getEnd();

				// 阅读表插入
				foreach ($pid as $key => $value){

					if (substr($value,0,4) == 'user') {
						$user_id = substr($value,5,13);

						// 查找阅读表
						$read_data = $this->model->notice->getReadRow($notice_end['notice_id'],$user_id);

						if (empty($read_data)) {

							$info = array(
							"notice_id"   			=> $notice_end['notice_id'],
							"read_to"     			=> $user_id,
							"read_form"   			=> $this->user['user_id'],
							"is_read"     			=> 0,
							"status"                => 1,
							"create_time"           => date("Y-m-d H:i:s"),
							"update_time"           => "0000-00-00 00:00:00",
							);
							$this->db->do_insert("tbl_notice_read", $info);

						}
					}
				}
				$info = array(
				"notice_id"   			=> $notice_end['notice_id'],
				"read_to"     			=> $this->user['user_id'],
				"read_form"   			=> $this->user['user_id'],
				"is_read"               => 0,
				"status"                => 1,
				"create_time"           => date("Y-m-d H:i:s"),
				"update_time"           => "0000-00-00 00:00:00",
				);
				$this->db->do_insert("tbl_notice_read", $info);
				if ($notice_type==3) {
					// 跳转
					Helper_Client::location("发布成功", "index.php?a=notice.commonissuelist");
				}else {
					// 跳转
					Helper_Client::location("发布成功", "index.php?a=notice.publicitylist");

				}

			}
			//  树状图
			// 所有部门名称
			$department_lists = $this->model->department->getAll();
			// 所有部门任职人员
			$department_name = $this->model->appoint->getSAll();
			foreach ($department_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$department_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
				$department_name[$key]['staff_name'] = $row['staff_name'];
			}

			// 所有教研组名称
			$research_lists = $this->model->research->getAll();
			// 所有教研组的任职人员
			$research_name = $this->model->appoint->getRAll();
			foreach ($research_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$research_name[$key]['staff_name'] = $row['staff_name'];
				$research_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			}

			// 所有备课组名称
			$prepare_lists = $this->model->prepare->getAll();
			// 所有备课组的任职人员
			$prepare_name = $this->model->appoint->getPAll();
			foreach ($prepare_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$prepare_name[$key]['staff_name'] = $row['staff_name'];
				$prepare_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			}

			// 学科组
			$discipline_lists = $this->model->discipline->getAll();
			// 所有备课组的任职人员
			$discipline_name = $this->model->appoint->getDAll();
			foreach ($discipline_name as $key => $value){
				$row = $this->model->staff->getinfo($value['staff_id']);
				$discipline_name[$key]['staff_name'] = $row['staff_name'];
				$discipline_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			}

			// 年级列表
			$grade_lists = $this->model->grade->getIni();
			// 班级列表
			$class_lists = $this->model->class->getAll();
			// 学生按 年级 班级 列出
			$student_lists = $this->db->fetchAll("SELECT a.user_id,b.student_name,b.class_id,b.grade_id FROM `tbl_user` AS a,`tbl_student` AS b WHERE a.type_id=b.student_id");

			$this->tpl->assign("department_lists", $department_lists);
			$this->tpl->assign("department_name", $department_name);
			$this->tpl->assign("research_lists", $research_lists);
			$this->tpl->assign("research_name", $research_name);

			$this->tpl->assign("prepare_lists", $prepare_lists);
			$this->tpl->assign("prepare_name", $prepare_name);
			$this->tpl->assign("discipline_lists", $discipline_lists);
			$this->tpl->assign("discipline_name", $discipline_name);

			$this->tpl->assign("grade_lists", $grade_lists);
			$this->tpl->assign("class_lists", $class_lists);
			$this->tpl->assign("student_lists", $student_lists);

			$this->tpl->display('notice/m.common.add.tpl.php');
		}
		/** ----------------------------- 通知审核 ---------------------------- **/
		/** 审核列表 **/
		public function actionCheckList ()
		{
			// 通用事项需要审批
			$notice_tye  =3;
			// 全部审核状态
			$show_lists  	= $this->inform_judge;
			// 查询条件
			$is_show		= $this->get->is_show;
			$where = " ";

			//搜索条件
			if(!empty($is_show)){

				$where .= " AND is_show='{$is_show}'";
				$this->tpl->assign("is_show", $is_show);
			}
			if($is_show=='0'){

				$where .= " AND is_show='{$is_show}'";
				$this->tpl->assign("is_show", $is_show);
			}
			// 审核人
			$audit_lists = $this->model->audit->getInfoAll($this->user['type_id']);

			if (empty($audit_lists)) {
				Helper_Client::alert("您无权限进入");
			}

			foreach ($audit_lists as $key=>$value){
				// 部门
				if ($value['audit_type'] == 'department') {
					$row['department'][$key] = $value['type_id'];
				}
				// 教研组
				if ($value['audit_type'] == 'research') {
					$row['research'][$key] = $value['type_id'];
				}
				// 备课组
				if ($value['audit_type'] == 'prepare') {
					$row['prepare'][$key] = $value['type_id'];
				}
				// 学科组
				if ($value['audit_type'] == 'discipline') {
					$row['discipline'][$key] = $value['type_id'];
				}
				// 级长
				if ($value['audit_type'] == 'grade') {
					$row['grade'][$key] = $value['type_id'];
				}
			}

			foreach ($row as $key => $value){
				if($key=='department'){
					$department = implode(',',$value);
				}
				if($key=='research'){
					$research = implode(',',$value);
				}
				if($key=='prepare'){
					$prepare = implode(',',$value);
				}
				if($key=='discipline'){
					$discipline = implode(',',$value);
				}
				if($key=='grade'){
					$grade = implode(',',$value);
				}
			}


			$wheres = " ";
			if (!empty($department)){
				$wheres .= "  ( audit_type='department' AND type_id IN ($department) AND notice_type = '{$notice_tye}') {$where}";
			}
			if (!empty($research)){
				$wheres .= " OR ( audit_type='research' AND type_id IN ($research) AND notice_type = '{$notice_tye}') {$where}";
			}
			if (!empty($prepare)){
				$wheres .= " OR ( audit_type='prepare' AND type_id IN ($prepare) AND notice_type = '{$notice_tye}') {$where}";
			}
			if (!empty($discipline)){
				$wheres .= " OR ( audit_type='discipline' AND type_id IN ($discipline) AND notice_type = '{$notice_tye}') {$where}";
			}
			if (!empty($grade)){
				$wheres .= " OR ( audit_type='grade' AND type_id IN ($grade) AND notice_type = '{$notice_tye}') {$where}";
			}

			$notice_lists = $this->db->fetchAll("SELECT * FROM `tbl_notice`  WHERE    {$wheres} ORDER BY notice_id DESC ");

			foreach ($notice_lists as $key => $value){
				// 审核
				$notice_lists[$key]['is_show'] = $this->inform_judge[$value['is_show']];
				// 部门名称
				$row = $this->model->department->getinfo($value['department_id']);
				$notice_lists[$key]['department_name']= $row['department_name'];
				// 内容解密
				$notice_lists[$key]['notice_content'] = base64_decode($notice_lists[$key]['notice_content']);
				// 控制标题字数
				$notice_lists[$key]['notice_title'] = mb_substr($value['notice_title'],0,30,'utf8');
				if(strlen($notice_lists[$key]['notice_title'])>10){
					$notice_lists[$key]['notice_title']=$notice_lists[$key]['notice_title'].'...';

				}
			}
			
			$this->tpl->assign("notice_lists", $notice_lists);
			$this->tpl->assign("user", $this->user['user_id']);
			$this->tpl->assign("department_lists", $department_lists);

			$this->tpl->assign("notice_type", $notice_type);
			$this->tpl->assign("show_lists", $show_lists);
			$this->tpl->display('notice/m.check.list.tpl.php');
		}
		/** 审核 **/
		public function actionCheckUpdate ()
		{
			$notice_id		= $this->get->notice_id;
			$notice_data 	= $this->model->notice->getInfo($notice_id);
			$notice_data['notice_content'] = base64_decode($notice_data['notice_content']);
			// 部门名称

			if ($notice_data['audit_type'] == 'department') {
				$name 	= $this->model->department->getInfo($notice_data['type_id']);
				$notice_data['name'] = $name['department_name'];
			}
			// 教研组
			if ($notice_data['audit_type'] == 'research') {

				$notice_data['name'] = '教研组';
			}
			// 备课组
			if ($notice_data['audit_type'] == 'prepare') {

				$notice_data['name'] = '备课组';
			}
			// 学科组
			if ($notice_data['audit_type'] == 'discipline') {

				$notice_data['name'] = '学科组';
			}
			// 级长
			if ($notice_data['audit_type'] == 'grade') {

				$notice_data['name'] = '级长';
			}
			if ($_POST) {
				$notice_content		= $this->post->notice_content;
				$is_show			= $this->post->is_show;
				$notice_opinion		= $this->post->notice_opinion;
				$notice_ffile		= $this->post->notice_ffile;

				// 写入数据库
				$info = array(

				"notice_content"		=> $notice_content,
				"is_show"				=> $is_show,
				"notice_opinion"		=> $notice_opinion,
				"notice_ffile"			=> $notice_ffile,
				"check_time"			=> date("Y-m-d"),

				);

				$this->db->do_update("tbl_notice", $info, "notice_id='{$notice_id}'");

				// 附件上传
				$file = $this->model->file->upload("notice_ffile", $notice_id, array("txt","ppt","xls","xlsx","docs","docx","doc","pdf","jpg","png","gif","zip","rar"));

				if (!empty($file)){
					$info = array(
					"notice_ffile" => $file['fname'],
					);

					$this->db->do_update("tbl_notice", $info, "notice_id='{$notice_id}'");
				}

				// 跳转
				Helper_Client::location("操作成功", "index.php?a=notice.checklist");

			}
			// 阅读人员记录，学生，老师
			$department_name = $this->model->notice->getReadAll($notice_id);
			foreach ($department_name as $key => $value){
				$row = $this->model->user->getInfo($value['read_to']);
				if($row['user_type']=='staff'){
					$c = $this->model->user->getNameById($row['user_id']);
					if (!empty($c)) {
						$staff_name[$key]['staff_name'] = $c;
						$staff_name[$key]['is_read'] = $value['is_read'];
					}

				}
				if($row['user_type']=='student'){
					$c = $this->model->user->getNameById($row['user_id']);
					if (!empty($c)) {
						$student_name[$key]['student_name'] = $c;
						$student_name[$key]['is_read'] = $value['is_read'];
					}
				}

				// 判断是否阅读
				$row = $this->model->notice->getReadInfo($value['staff_id']);
				$department_name[$key]['is_read'] = $row['is_read'];
			}

			$this->tpl->assign("staff_name", $staff_name);
			$this->tpl->assign("student_name", $student_name);

			$this->tpl->assign("notice_data", $notice_data);
			$this->tpl->display('notice/m.check.update.tpl.php');
		}
		/** ------------------------------ 公示 ------------------------------ **/
		/** 公示列表 **/
		public function actionPublicityList()
		{

			// 发布部门
			$department_lists = $this->model->department->getAll();

			// 查询条件
			$notice_title		= $this->get->notice_title;
			$department_id		= $this->get->department_id;
			$from				= $this->get->from;
			$to					= $this->get->to;
			$where = " ";
			//搜索条件
			if(!empty($notice_title)){

				$where .= " AND a.notice_title LIKE '%{$notice_title}%'";
				$this->tpl->assign("notice_title", $notice_title);
			}
			if(!empty($department_id)){

				$where .= " AND a.department_id ='{$department_id}'";
				$this->tpl->assign("department_id", $department_id);
			}
			if(!empty($from)){

				$where .= " AND a.create_time >= '{$from}'";
				$this->tpl->assign("from", $from);
			}
			if(!empty($to)){

				$where .= " AND a.create_time <= '{$to}+1'";
				$this->tpl->assign("to", $to);
			}
			$this->tpl->assign('uid',$this->user['user_id']);
			// 1=公示
			$notice_type  =1;
			

			$notice_lists = $this->db->fetchAll("SELECT * FROM `tbl_notice` AS a,`tbl_notice_read` AS b  WHERE a.notice_id=b.notice_id AND  b.read_to ='{$this->user['user_id']}' AND a.notice_type = '{$notice_type}'  {$where} ORDER BY a.notice_id DESC ");

			foreach ($notice_lists as $key => $value){
				// 部门名称
				$row = $this->model->department->getinfo($value['department_id']);
				$notice_lists[$key]['department_name']= $row['department_name'];
				// 内容解密
				$notice_lists[$key]['notice_content'] = base64_decode($notice_lists[$key]['notice_content']);
				// 控制标题字数
				$notice_lists[$key]['notice_title'] = mb_substr($value['notice_title'],0,30,'utf8');
				if(strlen($notice_lists[$key]['notice_title'])>10){
					$notice_lists[$key]['notice_title']=$notice_lists[$key]['notice_title'].'...';
					// 审核状态
					$notice_lists[$key]['is_show'] = $this->inform_judge[$value['is_show']];
				}

			}

			
			$this->tpl->assign("notice_lists", $notice_lists);
			$this->tpl->assign("user", $this->user['user_id']);
			$this->tpl->assign("department_lists", $department_lists);

			$this->tpl->assign("notice_type", $notice_type);
			$this->tpl->assign("appoint_lists", $appoint_lists);
			$this->tpl->display('notice/m.publicity.list.tpl.php');
		}

		/** -------------------------- 家校互动 --------------------------- **/
		/** 通用事项--家长写信列表 **/
		public function actionFamilyList()
		{
			// 4=家长写信
			$notice_type  =4;
			// 搜索
			$notice_title	= $this->get->notice_title;
			$from			= $this->get->from;
			$to				= $this->get->to;
			$where = "";

			if (!empty($notice_title)){
				$where = " AND notice_title LIKE '%{$notice_title}%' ";
				$this->tpl->assign("notice_title", $notice_title);
			}
			if (!empty($from)){
				$where = " AND create_time >='{$from}' ";
				$this->tpl->assign("from", $from);
			}if (!empty($to)){
				$where = " AND create_time <='{$to}+1' ";
				$this->tpl->assign("to", $to);
			}
			// 分页
			YOU::loadLib('page', "", '0');
			$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_notice` WHERE notice_type = '{$notice_type}' AND user_id ='{$this->user['user_id']}'  {$where}");
			$count = $tmp['count'];
			$page_total = ceil($count/PAGE_LIMIT);
			// 当前页
			$p = intval($_GET['p']);
			if ($p == 0){
				$p  = 1;
			}
			if ($p > 1){
				$start = PAGE_LIMIT * ($p-1);
			}else{
				$start = 0;
			}

			$notice_lists = $this->db->fetchAll("SELECT * FROM `tbl_notice`  WHERE notice_type = {$notice_type} AND user_id ={$this->user['user_id']}  {$where} ORDER BY notice_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
			foreach ($notice_lists as $key => $value){
				// 时间转换
				$notice_lists[$key]['create_time'] = date('Y-m-d',strtotime($value['create_time']));
				// 内容解密
				$row = base64_decode($value['notice_content']);
				// 控制内容字数
				$notice_lists[$key]['notice_content'] 	= mb_substr($row,0,30,'utf8');
				if(strlen($notice_lists[$key]['notice_content'])>10){
					$notice_lists[$key]['notice_content']=mb_substr($notice_lists[$key]['notice_content'],0,10,utf8).'...';
				}
			}

			$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
			$page->next_page   = '下一页>';
			$page->pre_page    = '<上一页';
			$page->style_path  = "static/page_style";
			$this->tpl->assign("page", $page->show(4, "yahoo"));

			$this->tpl->assign("notice_lists", $notice_lists);
			$this->tpl->display('notice/family.list.tpl.php');
		}
		/** 通用事项--家长写信添加 **/
		public function actionFamilyAdd()
		{

			// 家长姓名 临时测试
			$student_data = $this->model->student->getinfo($this->user['user_id']);
			$family_name = explode('，',$student_data['student_parent']);

			// 班主任
			$teacher_data = $this->model->student->getteacher($student_data['student_id']);

			if ($_POST){

				$notice_title      	= $this->post->notice_title;
				$notice_to      	= $this->post->notice_to;
				$notice_content     = $this->post->notice_content;
				$notice_form      	= $this->post->notice_form;
				$notice_content = base64_encode($notice_content);
				// 4=家长写信
				$notice_type = 4;
				// 传值1 ， $notice_to =老师id； 0就是学校
				if ($notice_to==1) {
					// 班主任
					$notice_to = $this->model->student->getteacher($student_data['student_id']);
				}

				// 发送者如果是学生 就为空，调用student_name
				if ($notice_form == '0') {
					$notice_form="";
				}

				// 写入数据库
				$info = array(

				"notice_title"      => $notice_title,
				"notice_to"     	=> $notice_to['staff_id'],
				"notice_content"    => $notice_content,
				"notice_form"     	=> $notice_form,
				"notice_type"     	=> $notice_type,
				"user_id"     		=> $this->user['user_id'],
				"status"           	=> 1,
				"create_time"      	=> date("Y-m-d H:i:s"),
				"update_time"      	=> "0000-00-00 00:00:00",
				);

				$this->db->do_insert("tbl_notice", $info);
				// 跳转
				Helper_Client::location("添加成功", "index.php?a=notice.familylist");
			}
			$this->tpl->assign("student_data", $student_data);
			$this->tpl->assign("family_name", $family_name);
			$this->tpl->display('notice/family.add.tpl.php');
		}
		/** 通用事项--家长写信查看 **/
		public function actionFamilyDetails()
		{
			$notice_id = $this->get->notice_id;
			$notice_data = $this->model->notice->getinfo($notice_id);
			$notice_data['notice_content'] = base64_decode($notice_data['notice_content']);
			// 阅读
			$info = array(
			"is_read"     			=> 1,
			);
			$this->db->do_update("tbl_notice_read", $info, "notice_id='{$notice_id}' AND read_to='{$this->user['user_id']}'");
			// 时间转换
			$notice_data['create_time'] = date('Y-m-d',strtotime($notice_data['create_time']));
			// 获取学生名称
			$r = $this->model->student->getinfo($notice_data['user_id']);
			$notice_data['student_name'] = $r['student_name'];

			$this->tpl->assign("notice_data", $notice_data);
			$this->tpl->display('notice/m.family.details.tpl.php');
		}
		/** 通用事项--家长写信删除 **/
		public function actionFamilyDel()
		{
			$notice_id = $this->get->notice_id;
			$notice_data = $this->db->fetchRow("select * from `tbl_notice` WHERE `user_id` = {$notice_id}");
			$uid = $this->user['user_id'];

			if($notice_data['user_id']  && ($uid !=$notice_data['user_id']) ){
				Helper_Client::alert("对不起无此权限");
				exit;
			}
			$this->db->query("DELETE  FROM `tbl_notice` WHERE notice_id='{$notice_id}'");

			// 跳转
			Helper_Client::location("删除成功", "index.php?a=notice.familylist");
		}
		/** 班主任管理--家长反馈 **/
		public function actionFamilyTercherList()
		{

			// 4=家长反馈
			$notice_type  =4;
			// 搜索
			$student_name	= $this->get->student_name;
			$from			= $this->get->from;
			$to				= $this->get->to;
			$where = "";

			if (!empty($student_name)){
				$row = $this->model->user->getIdByMName($student_name);

				$where = " AND user_id ='{$row}' ";
				$this->tpl->assign("student_name", $student_name);
			}
			if (!empty($from)){
				$where = " AND create_time >='{$from}' ";
				$this->tpl->assign("from", $from);
			}if (!empty($to)){
				$where = " AND create_time <='{$to}+1' ";
				$this->tpl->assign("to", $to);
			}
			
			// 接收的信息为（notice_type=4，班主任的学生）notice_to=老师的id
			$notice_lists = $this->db->fetchAll("SELECT * FROM `tbl_notice`  WHERE notice_type = '{$notice_type}' AND notice_to ='{$this->user['user_id']}'  {$where} ORDER BY notice_id DESC ");
			foreach ($notice_lists as $key => $value){
				// 时间转换
				$notice_lists[$key]['create_time'] = date('Y-m-d',strtotime($value['create_time']));
				// 内容解密
				$row = base64_decode($value['notice_content']);
				// 控制内容字数
				$notice_lists[$key]['notice_content'] 	= mb_substr($row,0,30,'utf8');
				if(strlen($notice_lists[$key]['notice_content'])>10){
					$notice_lists[$key]['notice_content']=mb_substr($notice_lists[$key]['notice_content'],0,10,utf8).'...';
				}
				// 学生姓名
				$notice_lists[$key]['student_name'] = $this->model->user->getNameById($value['user_id']);
				// 学生的id
				$row = $this->model->user->getinfo($value['user_id']);

				$notice_lists[$key]['student_id'] = $row['type_id'];
			}

			if ($_POST) {
				$notice_contents	= $this->post->notice_contents;
				$notice_id			= $this->post->notice_id;

				// 写入数据库
				$info = array(
				"notice_contents"	=>$notice_contents,
				);
				$this->db->do_update("tbl_notice", $info, "notice_id='{$notice_id}'");
			}

			$this->tpl->assign("notice_lists", $notice_lists);
			$this->tpl->display('notice/family.teacher.list.tpl.php');
		}
		/** 校长室管理--家长互动 **/
		public function actionSchoolList()
		{

			// 4=家长反馈
			$notice_type  =4;
			// 搜索
			$student_name	= $this->get->student_name;
			$from			= $this->get->from;
			$to				= $this->get->to;
			$where = "";

			if (!empty($student_name)){
			
				$row = $this->model->user->getIdByMName($student_name);
				$where .= " AND user_id ='{$row}' ";
				$this->tpl->assign("student_name", $student_name);
			}
			if (!empty($from)){
				$where .= " AND create_time >='{$from}' ";
				$this->tpl->assign("from", $from);
			}if (!empty($to)){
				$where .= " AND create_time <='{$to}+1' ";
				$this->tpl->assign("to", $to);
			}
			
			// notice_to=0 全体学校
			$notice_lists = $this->db->fetchAll("SELECT * FROM `tbl_notice`  WHERE notice_type = {$notice_type} AND notice_to ='0'  {$where} ORDER BY notice_id DESC ");
			
			foreach ($notice_lists as $key => $value){
				// 时间转换
				$notice_lists[$key]['create_time'] = date('Y-m-d',strtotime($value['create_time']));
				// 内容解密
				$row = base64_decode($value['notice_content']);
				// 控制内容字数
				$notice_lists[$key]['notice_content'] 	= mb_substr($row,0,30,'utf8');
				if(strlen($notice_lists[$key]['notice_content'])>10){
					$notice_lists[$key]['notice_content']=mb_substr($notice_lists[$key]['notice_content'],0,10,utf8).'...';
				}
				// 学生姓名
				$notice_lists[$key]['student_name'] = $this->model->user->getNameById($value['user_id']);
				// 学生的id
				$row = $this->model->user->getinfo($value['user_id']);
				$notice_lists[$key]['student_id'] = $row['type_id'];
			}

			if ($_POST) {
				$notice_contents	= $this->post->notice_contents;
				$notice_id			= $this->post->notice_id;

				// 写入数据库
				$info = array(
				"notice_contents"	=>$notice_contents,
				);
				$this->db->do_update("tbl_notice", $info, "notice_id='{$notice_id}'");
			}
			

			$this->tpl->assign("notice_lists", $notice_lists);

			$this->tpl->display('notice/m.school.list.tpl.php');
		}
		/** ------------------------------------ 下载 ----------------------------------- **/
		/** 下载**/
		public function actionoutput(){
			$fname = $this->get->notice_file;
			$fpath = UPLOAD_PATH."/notice_file/{$fname}";

			// 输出下载文件头s
			header("Content-Disposition: attachment; filename={$fname}");
			// 在线输出
			readfile($fpath);

		}
		//家长 我的通知  1学校通知  2班主任通知
		public function actionmynotice(){
			$student_id = $this->user['student_id'];
			$class_id = $this->user['class_id'];
			$user_id = $this->user['user_id'];
			$row = $this->db->fetchRow("SELECT * FROM `tbl_appoint` WHERE class_id = '{$class_id}'");
			$uid = $this->model->user->getIdByType('staff',$row['staff_id']);
			$ntype = $this->get->ntype;
			if($ntype==2){//班主任通知
				//1获取班主任
				$notice_lists = $this->db->fetchAll("SELECT * FROM	 `tbl_notice` as a,`tbl_notice_read` as b WHERE a.notice_id = b.notice_id AND a.user_id ='{$uid}' AND b.read_to ='{$user_id}'");
			}else{//默认
				$notice_lists = $this->db->fetchAll("SELECT * FROM	 `tbl_notice` as a,`tbl_notice_read` as b WHERE a.notice_id = b.notice_id AND b.read_to ='{$user_id}' AND a.user_id !='{$uid}'");
			}
			$this->tpl->assign("notice_lists",$notice_lists);
			$this->tpl->display('notice/m.mynotice.tpl.php');
		}
		//家校互动
		public function actionmyfamily(){
			$class_id = $this->user['class_id'];
			$user_id = $this->user['user_id'];
			$row = $this->db->fetchRow("SELECT * FROM `tbl_appoint` WHERE class_id = '{$class_id}'");
			$uid = $this->model->user->getIdByType('staff',$row['staff_id']);
			$notice_lists = $this->db->fetchAll("SELECT * FROM	 `tbl_notice` as a,`tbl_notice_read` as b WHERE (a.notice_id = b.notice_id AND b.read_to ='{$user_id}') OR (a.user_id='{$user_id}') ORDER BY a.create_time ");
			//回复
			if ($_POST) {
				$notice_contents		= $this->post->notice_contents;
				$notice_id			= $this->post->notice_id;
				// 写入数据库
				$info = array(

					"notice_contents"		=> $notice_contents,

				);
				$this->db->do_update("tbl_notice", $info, "notice_id='{$notice_id}'");
			}

			$this->tpl->assign("user_id",$user_id);//我的id
			$this->tpl->assign("uid",$uid);//班主任id
			$this->tpl->assign("notice_lists",$notice_lists);
			$this->tpl->display('notice/m.myfamily.tpl.php');
		}


	}

?>	